﻿﻿
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
    <!-- 日期框 -->
    <link rel="stylesheet" href="static/ace/css/datepicker.css"/>
    <link rel="stylesheet" href="static/styles/base.css"/>
</head>
<body class="no-skin">

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">

                        <!-- 检索  -->
                        <form action="bill/list.do" method="post" name="goodsForm" id="goodsForm">
                            <table style="margin-top:5px;">
                                <tr>
                                  <td>
                                        <div class="nav-search">
									<span class="input-icon">
										<input class="nav-search-input" autocomplete="off" id="pet_name" type="text"
                                               name="pet_name" value="${pd.pet_name}" placeholder="这里输入用户昵称"/>
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="nav-search">
									<span class="input-icon"><input class="nav-search-input" autocomplete="off" id="phone" type="text"
                                               name="phone" value="${pd.phone}" placeholder="这里输入手机号码"/><i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
                                        </div>
                                    </td>
                                    <td class="zdyTime" style="padding-left:5px;"> <input class="span10 date-picker" name="LongTerm" id="LongTerm" value="${pd.LongTerm}" type="text" style="width:88px;" placeholder="选择月份"  title="选择月份"/></td>
                                    <td class="center" style="padding-left:5px;"> 自定义时间 </td>
                                    
                                    <td class="input-daterange"> 
                                    	<div class="dib vm pl5"><input class="span10 date-picker" name="startTime" id="startTime" value="${pd.startTime}" type="text"  style="width:88px;" placeholder="选择日期" title="选择日期"/></div>
                                    	<div class="dib vm pl5">至</div>
                                    	<div class="dib vm pl5"><input class="span10 date-picker" name="endTime" id="endTime" value="${pd.endTime}" type="text" style="width:88px;" placeholder="选择日期" title="选择日期"/></div>
                                    </td>
                                    <td class="center" style="padding-left:5px;">
                                        	账单类型:
                                    </td>
                                     <td style="vertical-align:top;padding-left:5px;">
                                        <select class="chosen-select form-control" name="type" id="type"
                                                data-placeholder="支付类型" style="vertical-align:top;width: 100px;">
                                            <option value="">全部</option>
                                            <option value="00" <c:if test="${pd.type=='00'}">selected</c:if>>消费
                                            </option>
                                            <option value="02" <c:if test="${pd.type=='02'}">selected</c:if>>奖励
                                            </option>
                                            <option value="03" <c:if test="${pd.type=='03'}">selected</c:if>>提现
                                            </option>
                                        </select>
                                    </td>
                                    <c:if test="${QX.cha == 1 }">
                                        <td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs"
                                                                                            onclick="searchs();"
                                                                                            title="检索"><i
                                                id="nav-search-icon"
                                                class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a>
                                        </td>
                                    </c:if>
                                    <c:if test="${QX.toExcel == 1 }">
                                        <td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs"
                                                                                            onclick="toExcel();"
                                                                                            title="导出到EXCEL"><i
                                                id="nav-search-icon"
                                                class="ace-icon fa fa-download bigger-110 nav-search-icon blue"></i></a>
                                        </td>
                                    </c:if>
                                </tr>
                            </table>
                            <!-- 检索  -->
							<div style="padding-top:30px;">
								<span>收入：${inToPrice } (元)</span>
								<span>支出：${outToPrice } (元)</span>
							</div>
                            <table id="simple-table" class="table table-striped table-bordered table-hover"
                                   style="margin-top:5px;">
                                <thead>
                                <tr>
                                    <th class="center" style="width:50px;">排序</th>
                                    <th class="center">ID</th>
                                    <th class="center">支付编码</th>
                                    <th class="center">用户昵称</th>
                                    <th class="center">用户手机号</th>
                                    <th class="center">账单金额</th>
                                    <th class="center">支付金额</th>
                                    <th class="center">付款方式</th>
                                    <th class="center">金额状态</th>
                                    <th class="center">账单描述</th>
                                    <th class="center">账单类型</th>
                                    <th class="center">支付时间</th>
                                </tr>
                                </thead>

                                <tbody id="goodlist">

                                <!-- 开始循环 -->
                                <c:choose>
                                    <c:when test="${not empty billList}">
                                        <c:if test="${QX.cha == 1 }">
                                            <c:forEach items="${billList}" var="bill" varStatus="vs">

                                                <tr>
                                                    <td class='center' style="width: 30px;">${vs.index+1}</td>
                                                    <td class="center">${bill.id }</td>
                                                    <td class="center">${bill.code }</td>
                                                    <td class="center">${bill.pet_name }</td>
                                                    <td class="center">${bill.phone }</td>
                                                    <td class="center">${bill.total_price }</td>
                                                    <td class="center">${bill.pay_price }</td>
                                                    <td class="center"><c:if test="${bill.pay_mode!=null}"><c:if
                                                            test="${bill.pay_mode=='wechat'}">微信</c:if><c:if
                                                            test="${bill.pay_mode=='alipay'}">支付宝</c:if></c:if><c:if
                                                            test="${bill.pay_mode==null}">/</c:if></td>
                                                    <td class="center"><c:if
                                                            test="${bill.price_state=='01'}">支出</c:if><c:if
                                                            test="${bill.price_state=='02'}">收入</c:if></td>
                                                    <td class="center">${bill.remark }</td>
                                                    <td class="center">
                                                    		<c:if test="${bill.type=='00'}">消费</c:if><c:if
                                                            test="${bill.type=='01'}">充值</c:if><c:if
                                                            test="${bill.type=='02'}">奖励</c:if><c:if
                                                            test="${bill.type=='03'}">提现</c:if>
                                                            <c:if
                                                            test="${bill.type=='04'}">推荐支出 </c:if>
                                                            <c:if
                                                            test="${bill.type=='05'}">手续费</c:if>
                                                            <c:if
                                                            test="${bill.type=='06'}">复投</c:if>
                                                            <c:if
                                                            test="${bill.type=='07'}">复投消费</c:if></td>
                                                    <td class="center">${bill.finish_time }</td> 
                                                </tr>
                                            </c:forEach>
                                        </c:if>
                                        <c:if test="${QX.cha == 0 }">
                                            <tr>
                                                <td colspan="13" class="center">您无权查看</td>
                                            </tr>
                                        </c:if>
                                    </c:when>
                                    <c:otherwise>
                                        <tr class="main_info">
                                            <td colspan="13" class="center">没有相关数据</td>
                                        </tr>
                                    </c:otherwise>
                                </c:choose>
                                </tbody>
                            </table>

                            <%-- <table id="simple-table1" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
                                  <thead>
                                    <tr>
                                        <th class="center">进账 (RMB)</th>
                                        <th class="center">出账 (RMB)</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                       <td class="center">${pd.enter } 元</td>
                                       <td class="center">${pd.out } 元</td>
                                    </tr>
                                </tbody>
                            </table> --%>

                            <div class="page-header position-relative">
                                <table style="width:100%;">
                                    <tr>
                                        <!-- <td style="vertical-align:top;">
                                            <a class="btn btn-mini btn-success" onclick="statistics();">账单统计</a>
                                        </td> -->
                                        <td style="vertical-align:top;">
                                            <div class="pagination"
                                                 style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </form>

                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->

    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div>
<!-- /.main-container -->

<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- 删除时确认窗口 -->
<script src="static/ace/js/bootbox.js"></script>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- 日期框 -->
<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>

<script type="text/javascript">
    $(top.hangge());
    
    
    var spanDateFormat = 'yyyy-mm-dd';
    $('.input-daterange').datepicker({
    	  autoclose: true,
    	  format: "yyyy-mm-dd",
    	  maxViewMode: 0,
    	});
    
    $(".zdyTime input").datepicker({
    	 format: "yyyy-mm",
    	 startView: 1,
    	 minViewMode: 1,
    	 maxViewMode: 2,
    	 language: "zh-CN",
    	 autoclose: true
	});
    
    
    
    

    //检索
    function searchs() {
    	var startTime = $("#startTime").val();//开始时间
    	var endTime = $("#endTime").val();//结束时间
    	if(startTime!="" && endTime!=""){
    		$("#LongTerm").val('');
    	}
        top.jzts();
        $("#goodsForm").submit();
    }

    //对接
    function editDock(id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "对接信息";
        diag.URL = '<%=basePath%>goods/goDock.do?goods_id=' + id;
        diag.Width = 600;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }


    function statistics() {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "账单统计";
        diag.URL = '<%=basePath%>bill/statistics.do';
        diag.Width = 800;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                if ('${page.currentPage}' == '0') {
                    top.jzts();
                    setTimeout("self.location=self.location", 100);
                } else {
                    nextPage('${page.currentPage}');
                }
            }
            diag.close();
        };
        diag.show();
    }

    <%-- function toGoodsSpec(goodsId){
         top.jzts();
         var diag = new top.Dialog();
         diag.Drag=true;
         diag.Title ="设置规格";
         diag.URL = '<%=basePath%>goods/goodsSpecList.do?goodsId='+goodsId;
         diag.Width = 1200;
         diag.Height = 900;
         diag.CancelEvent = function(){ //关闭事件
             if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
                nextPage('${page.currentPage}');
            }
            diag.close();
         };
         diag.show();
    } --%>

    //查看
    function seeGoodInfo(goods_id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "查看";
        diag.URL = '<%=basePath%>goods/goSee.do?id=' + goods_id;
        diag.Width = 1000;
        diag.Height = 800;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    //修改
    function editGoods(goods_id, state) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "修改商品";
        diag.URL = '<%=basePath%>goods/goEditG.do?id=' + goods_id + '&state=' + state;
        diag.Width = 1200;
        diag.Height = 900;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    function seeGoods(goods_id, state) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "查看商品";
        diag.URL = '<%=basePath%>goods/goEditG.do?id=' + goods_id + '&state=' + state;
        diag.Width = 1200;
        diag.Height = 900;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    //修改促销
    function editGoodSale(id, discount, bidPrice, price) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "促销信息";
        diag.URL = '<%=basePath%>goods/goSales.do?goods_id=' + id + '&price=' + price;
        diag.Width = 800;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();

    }

    //修改上下架状态
    function editGoodsState(id, state, endTime) {
        $.get("<%=basePath%>goods/updateState.do", {
            id: id,
            state: state,
            endTime: endTime,
        }, function (data) {
            //这里显示从服务器返回的数据
            if ("success" == data) {
                alert("修改成功");
            } else if ("failed" == data) {
                alert("修改失败");
            } else if ("timeEnd" == data) {
                alert("此商品下架时间已到!");
            }
            /* else if("nospec"==data.substring(0,6)){
               alert("id为(  "+data.substring(6,data.length)+"  )的商品没有设置规格，无法上架");
           }else if("nounit"==data.substring(0,6)){
               alert("id为(  "+data.substring(6,data.length)+"  )的商品没有设置批发价单位，无法上架");
           }else if("noprice"==data.substring(0,7)){
               alert("id为(  "+data.substring(7,data.length)+"  )的商品批发价区间有误，无法上架");
           }else if("noship"==data.substring(0,6)){
               alert("id为(  "+data.substring(6,data.length)+"  )的商品未设置发货地，无法上架");
           }else if("notime"==data.substring(0,6)){
               alert("id为(  "+data.substring(6,data.length)+"  )的商品下架时间已到，无法上架");
           } */
            nextPage('${page.currentPage}');
        });
    }


    //排序编辑
    $(function () {
        $('.date-picker').datepicker({autoclose: true, todayHighlight: true});
        var tdObj = "";
        var oldText = "";
        var inputObj = "";
        var newText = "";
        var id = "";
        if ('${QX.edit}' == 1) {
            //给这些单元格注册鼠标点击事件
            $("#goodlist tr").each(function () {
                $(this).children('#seq').click(function () {
                    id = $(this).next().text();//获取下一个同级元素，即id
                    //找到当前鼠标单击的td
                    tdObj = $(this);
                    //保存原来的文本
                    oldText = $(this).text();
                    //创建一个文本框
                    inputObj = $("<input type='text' value='" + oldText + "'/>");
                    //去掉文本框的边框
                    inputObj.css("border-width", 0);
                    inputObj.click(function () {
                        return false;
                    });
                    //使文本框的宽度和td的宽度相同
                    inputObj.width(tdObj.width());
                    inputObj.height(tdObj.height());
                    //去掉文本框的外边距
                    inputObj.css("margin", 0);
                    inputObj.css("padding", 0);
                    inputObj.css("text-align", "center");
                    inputObj.css("font-size", "16px");
                    inputObj.css("background-color", tdObj.css("background-color"));
                    //把文本框放到td中
                    tdObj.html(inputObj);
                    //文本框失去焦点的时候变为文本
                    inputObj.blur(function () {
                        newText = $(this).val();
                        if (!isInt(newText) || newText.length > 8) {
                            alert("只能输入最多8位整数");
                            tdObj.html(oldText);
                        } else {
                            $.get("goods/updateSeq.do?id=" + id + '&seq=' + newText, function (data, status) {
                                if (data == "success") {
                                    tdObj.html(newText);
                                }
                                else {
                                    tdObj.html(oldText);
                                }
                            });
                        }

                    });
                });
            });
        }
    });

    //检查是否为正整数
    function isInt(a) {
        var reg = /^\d+$/;
        return reg.test(a);
    }

    function toGoodsSpec(goodId) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "设置规格";
        diag.URL = '<%=basePath%>goods/goodsSpecList.do?goodsId=' + goodId;
        diag.Width = 800;
        diag.Height = 300;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }


    function toGoodsUnit(goodsId) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "设置商品发货地";
        diag.URL = '<%=basePath%>goods/goodsUnitList.do?goodsId=' + goodsId;
        diag.Width = 700;
        diag.Height = 300;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    function toGoodsPrice(goodsId) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "设置批发价区间";
        diag.URL = '<%=basePath%>goods/goodsPriceList.do?goodsId=' + goodsId;
        diag.Width = 800;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    //复选框全选控制
    var active_class = 'active';
    $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function () {
        var th_checked = this.checked;//checkbox inside "TH" table header
        $(this).closest('table').find('tbody > tr').each(function () {
            var row = this;
            if (th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
            else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
        });
    });

    //批量上架
    function batchUpState() {
        var str = '';
        var state = '';
        for (var i = 0; i < document.getElementsByName('ids').length; i++) {
            if (document.getElementsByName('ids')[i].checked) {
                if (document.getElementsByName('ids')[i].id != '00') {
                    alert("存在已上架商品");
                    return false;
                }
                if (str == '') {
                    str += document.getElementsByName('ids')[i].value;
                } else {
                    str += ',' + document.getElementsByName('ids')[i].value;
                }
            }
        }
        if (str == '') {
            alert("您没有选择任何商品");
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: '<%=basePath%>goods/updateBatchState.do?tm=' + new Date().getTime(),
                data: {state: '01', ids: str},
                success: function (data) {
                    if ("success" == data) {
                        alert("批量上架成功");
                    } else if ("timeEnd" == data.substring(0, 7)) {
                        alert("id为(  " + data.substring(7, data.length) + "  )的商品下架时间已到，无法上架");
                    } else {
                        alert("批量上架失败");
                    }
                    nextPage('${page.currentPage}');

                }
            });
        }
    }

    //导出excel
    function toExcel() {
        var phone = $("#phone").val();
        var pet_name = $("#pet_name").val();
        var LongTerm = $("#LongTerm").val();
        var type = $("#type").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var pageNum = '${page.currentPage}';
        window.location.href = '<%=basePath%>bill/excel.do?phone=' + phone + '&LongTerm=' + LongTerm + '&startTime=' + startTime +'&endTime=' + endTime + '&pageNum=' + pageNum +'&pet_name=' + pet_name + '&type=' + type;
    }

    //批量下架
    function batchDownState() {
        var str = '';
        var state = '';
        for (var i = 0; i < document.getElementsByName('ids').length; i++) {
            if (document.getElementsByName('ids')[i].checked) {
                if (document.getElementsByName('ids')[i].id != '01') {
                    alert("存在已下架商品");
                    return false;
                }
                if (str == '') str += document.getElementsByName('ids')[i].value;
                else str += ',' + document.getElementsByName('ids')[i].value;
            }
        }
        if (str == '') {
            alert("您没有选择任何商品");
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: '<%=basePath%>goods/updateBatchState.do?tm=' + new Date().getTime(),
                data: {state: '00', ids: str},
                success: function (data) {
                    if ("success" == data) {
                        alert("批量下架成功");
                    } else {
                        alert("批量下架失败");
                    }
                    nextPage('${page.currentPage}');

                }
            });
        }
    }

    //删除
    function delgood(id) {
        bootbox.confirm("确定要删除吗?", function (result) {
            if (result) {
                top.jzts();
                var url = "<%=basePath%>goods/delGood.do?id=" + id;
                $.get(url, function (data) {
                    if (data == "success") {
                        alert("删除成功");
                    }
                    else {
                        alert("删除失败");
                    }
                    nextPage('${page.currentPage}');
                });
            }
            ;
        });
    }

    //批量删除
    function delGoods() {
        var str = '';
        var state = '';
        for (var i = 0; i < document.getElementsByName('ids').length; i++) {
            if (document.getElementsByName('ids')[i].checked) {
                /* if(document.getElementsByName('ids')[i].id!='00'){
                      alert("存在已上架商品,请先下架再删除");
                      return false;
                  } */
                if (str == '') str += document.getElementsByName('ids')[i].value;
                else str += ',' + document.getElementsByName('ids')[i].value;
            }
        }
        if (str == '') {
            alert("您没有选择任何商品");
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: '<%=basePath%>goods/delGoods.do?tm=' + new Date().getTime(),
                data: {ids: str},
                success: function (data) {
                    if (data == "success") {
                        alert("批量删除成功");
                    }
                    else {
                        alert("批量删除失败");
                    }
                    nextPage('${page.currentPage}');
                }
            });
        }
    }

</script>
</html>
